package com.alfred.redis.controller;

import com.alfred.redis.annotation.ControllerLimit;
import com.alfred.redis.util.IpUtil;
import com.alfred.redis.vo.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/seckill")
@Slf4j
public class CurrentLimitController {


    /**
     * 接口限流，加入@ControllerLimit注解即可达到限流的效果
     *
     * @return
     */
    @ControllerLimit
    @RequestMapping("/current/limit")
    @ResponseBody
    public CommonResult currentLimit(HttpServletRequest request) {
        log.info("currentLimitController currentLimit request ip [{}]", IpUtil.getIpAddr(request));
        System.out.println(IpUtil.getIpAddr(request));
        return CommonResult.success(true);
    }


}
